﻿#ifndef LPPROCESSELLIPSE_H
#define LPPROCESSELLIPSE_H

#include <QObject>
#include <QWidget>
#include <QTimer>

/**
* @brief  进度条控件
* @author    Wanglipeng
* @email     1594932770@qq.com
* @date      2021-06-14
* 1.设置当前值
* 2.设置当前值颜色
* 2.设置最大最小值
* 3.设置顺时针逆时针旋转
* 4.显示进度值
* 5.设置圆环间距
* 6.设置圆环宽度
* 7.设置精确度
* 8.设置内圈外圈颜色
* 9.设置中心圈颜色
* 10.启动定时器更新进度条
*/

class LPProcessEllipsePrivate;
class LPProcessEllipse:public QWidget
{
    Q_OBJECT
    Q_PROPERTY(double currentValue READ getValue WRITE setValue)
    Q_PROPERTY(double minValue READ getMinValue WRITE setMinValue)
    Q_PROPERTY(double maxValue READ getMaxValue WRITE setMaxValue)
    Q_PROPERTY(bool clockWise READ getClockWise WRITE setClockWise)
    Q_PROPERTY(bool showPercent READ getShowPercent WRITE setShowPercent)
    Q_PROPERTY(int ringPadding READ getRingPadding WRITE setRingPadding)
    Q_PROPERTY(int ringWidth READ getRingWidth WRITE setRingWidth)
    Q_PROPERTY(int precision READ getPrecision WRITE setPrecision)
    Q_PROPERTY(QColor backgroundColor READ getBackgroundColor WRITE setBackgroundColor)
    Q_PROPERTY(QColor textColor READ getTextColor WRITE setTextColor)
    Q_PROPERTY(QColor ringColor READ getRingColor WRITE setRingColor)
    Q_PROPERTY(QColor ringBackgroundColor READ getRingBackgroundColor WRITE setRingBackgroundColor)

public:
    explicit LPProcessEllipse(QWidget *parent = nullptr);
    ~LPProcessEllipse();

    LPProcessEllipse& setValue(double value);
    LPProcessEllipse& setMinValue(double minValue);
    LPProcessEllipse& setMaxValue(double maxValue);
    LPProcessEllipse& setClockWise(bool clockWise);
    LPProcessEllipse& setShowPercent(bool showPercent);
    LPProcessEllipse& setRingPadding(int ringPadding);
    LPProcessEllipse& setRingWidth(int ringWidth);
    LPProcessEllipse& setPrecision(int precision);
    LPProcessEllipse& setBackgroundColor(const QColor &backgroundColor);
    LPProcessEllipse& setTextColor(const QColor &textColor);
    LPProcessEllipse& setRingColor(const QColor &ringColor);
    LPProcessEllipse& setRingBackgroundColor(const QColor &ringBackgroundColor);
    LPProcessEllipse& setCircleColor(const QColor &circleColor);

    double getValue() const;
    double getMinValue() const;
    double getMaxValue() const;
    bool getClockWise() const;
    bool getShowPercent() const;
    int getRingPadding() const;
    int getRingWidth() const;
    int getPrecision() const;
    QColor getBackgroundColor() const;
    QColor getTextColor() const;
    QColor getRingColor() const;
    QColor getRingBackgroundColor() const;
    QColor getCircleColor() const;

    void startTimer();

protected:
    void paintEvent(QPaintEvent *);
    void resizeEvent(QResizeEvent*);
    void drawBackground(QPainter *painter);
    void drawRing(QPainter *painter);
    void drawPadding(QPainter *painter);
    void drawCircle(QPainter *painter);
    void drawValue(QPainter *painter);

private:
    LPProcessEllipsePrivate *_P;
};

#endif // LPProcessEllipse_H
